package com.orange.adminapi.controller.floor;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.orange.core.service.floor.FloorService;
import com.orange.core.pojo.PageReqDto;
import com.orange.core.pojo.R;
import com.orange.core.pojo.entity.floor.dto.FloorDTO;
import com.orange.core.pojo.entity.floor.vo.FloorVO;
import com.orange.core.pojo.req.floor.FloorPageReq;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>ClassName:FloorController</p>
 * <p>Description: 楼层controller</p>
 * <p>Author: lwm</p>
 * <p>Date: 2025/5/24 18:08</p>
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/floor")
public class FloorController {

    private final FloorService floorService;

    /*@GetMapping("/list")
    public R<List<FloorVO>> list(){
        List<FloorVO> floorVOList = floorService.floorList();
        return R.ok(floorVOList);
    }*/

    /**
     * 楼层管理分页查询
     * @param pageReqDto
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).FLOOR_LIST.permission.identifier)")
    @PostMapping("/page")
    public R<Page<FloorVO>> page(@RequestBody PageReqDto<FloorPageReq> pageReqDto) {
        Page<FloorVO> page = floorService.page(pageReqDto);
        return R.ok(page);
    }

    /**
     * 楼层管理详情
     * @param id
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).FLOOR_INFO.permission.identifier)")
    @GetMapping("/info/{id}")
    public R<FloorVO> info(@PathVariable("id") Integer id){
        return R.ok(floorService.info(id));
    }

    /**
     * 楼层管理新增
     * @param floorDTO
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).FLOOR_SAVE.permission.identifier)")
    @PostMapping
    public R<Boolean> save(@RequestBody @Validated FloorDTO floorDTO){
        return R.ok(floorService.save(floorDTO));
    }

    /**
     * 楼层管理修改
     * @param floorDTO
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).FLOOR_UPDATE.permission.identifier)")
    @PutMapping
    public R<Boolean> update(@RequestBody @Validated FloorDTO floorDTO){
        return R.ok(floorService.update(floorDTO));
    }

    /**
     * 楼层管理批量删除
     * @param ids
     * @return
     */
    @PreAuthorize("hasAuthority(T(com.orange.core.pojo.enums.EPermission).FLOOR_DELETE.permission.identifier)")
    @DeleteMapping("/{ids}")
    public R<Boolean> remove(@PathVariable Integer[] ids){
        return R.ok(floorService.deleteFloorByIds(ids));
    }

}
